package com.wanmait.myhouse.mediatorController;

import com.wanmait.myhouse.dao.MediatorDAO;
import com.wanmait.myhouse.vo.Mediator;
import org.apache.taglibs.standard.extra.spath.Step;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("mediator")
public class MediatorLoginController {
    @GetMapping("exit")
    public String exit(HttpSession session){
        session.invalidate();
        return "redirect:/mediator/index";
    }
    @PostMapping("mediatorLogin")
    @ResponseBody
    public String mediatorLogin(Mediator mediator, HttpSession session){
        MediatorDAO mediatorDAO = new MediatorDAO();
        Mediator mediator1 = mediatorDAO.findBYMediatorNameAndMediatorPass(mediator);
        if (mediator1 == null){
            return "0";
        }else {
            session.setAttribute("mediator",mediator1);
            return "1";
        }
    }

    @GetMapping("login")
    public String login(){
        return "/mediator/login";
    }
}
